﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DTO;
using System.Data.SqlClient;
using System.Data;

namespace DAO
{
   public class NhanVienDAO
    {
       public List<NhanVienDTO> LayDanhSachNhanVien()
       {
           List<NhanVienDTO> listnhanvien = new List<NhanVienDTO>();
           SqlConnection conn = null;
           SqlDataReader reader = null;
           try
           {
               String sql = "Select * from NhanVien";

               conn = DataProvider.ConnectDB();
               SqlCommand cm = new SqlCommand(sql, conn);
               reader = cm.ExecuteReader();
               while (reader.Read())
               {
                   NhanVienDTO nvDTO = new NhanVienDTO();
                   nvDTO.MaNV = reader.GetInt32(0);
                   if (reader[1] != DBNull.Value)
                   {
                       nvDTO.TenNV = reader.GetString(1);
                   }
                   if (reader[2] != DBNull.Value)
                   {
                       nvDTO.NgaySinh = reader.GetDateTime(2);
                   }
                   if (reader[3] != DBNull.Value)
                   {
                       nvDTO.DiaChi = reader.GetString(3);
                   }
                   if (reader[4] != DBNull.Value)
                   {
                       nvDTO.DienThoai = reader.GetInt32(4);
                   }
                   if (reader[5] != DBNull.Value)
                   {
                       nvDTO.TaiKhoan = reader.GetString(5);
                   }
                   if (reader[6] != DBNull.Value)
                   {
                       nvDTO.MatKhau = reader.GetString(6);
                   }
                   if (reader[7] != DBNull.Value)
                   {
                       nvDTO.MaBP = reader.GetInt32(7);
                   }
                   listnhanvien.Add(nvDTO);
               }
           }
           catch (Exception ex)
           { String e = ex.ToString(); }
           finally
           { conn.Close(); }
           return listnhanvien;
       }
    }
}
